/// <reference path="../_References.ts"/>

class Powerup //missing  some code for loop to add more balls when there is not a ball
{
    public score = 100;
    public Location = null;
    public image = new Image();

    constructor()
    {
        this.image.src = 'images/powerup.jpg';

        var isValid;
        var randomx;
        var randomy;
        do
        {
            isValid = true;
            randomx = Math.floor(Math.random() * Game.terrain.width);
            randomy = Math.floor(Math.random() * Game.terrain.height);
            for (var i = 0; i < Game.snake.body.length; i++)
            {
                if (Game.snake.body[i].x == randomx && Game.snake.body[i].y == randomy)
                    isValid = false;
            }
        }
        while (isValid !== true);

        this.Location = new Point(randomx, randomy);  //Gives the possible values to the Location property of the ball
        //snake.score = snake.score + 1; //score will be snake.score - 1 (for the first time the ball spawn)
    }


    public draw = function()
    {
        var point = Game.terrain.getCoordinates(this.Location);
        Game.context.drawImage(this.image, point.x, point.y, Game.terrain.elementWidth - 1, Game.terrain.elementWidth - 1);
    };
}